<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Category extends CPT_Controller{
    function __construct(){
	parent::__construct();
    }
    
    /*
     * Fetches all categories and the amount of drinks each one contains
     */
    public function index(){
	$this->headline = 'Categories';
	
	$this->view_data['categories'] = Model\Category::with('drink')->all();
    }
    
    /*
     * Fetches category details
     */
    public function details($category_id = FALSE){
	if(FALSE == $category_id)
	    redirect('category');
	
	$this->view_data['category'] = Model\Category::with('drink')->find($category_id);
	$this->view_data['drinks']   = $this->view_data['category']->drink();
	
	$this->headline = 'Category: ' . $this->view_data['category']->name;
	
    }
    
    /**
     * 
     */
    public function drinks($category_id = FALSE){
        if(FALSE == $category_id)
	    redirect('category');
        
        $this->view_data['category'] = Model\Category::find($category_id);
        $this->view_data['drinks']   = $this->view_data['category']->drink();
        
        $this->headline = 'Drink recipes listed under ' . $this->view_data['category']->name;
    }
}
